package com.gmalllogger.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description: TODO QQ1667847363
 * @author: xiao kun tai
 * @date:2022/1/1 8:57
 */
@Slf4j
@RestController
public class LoggerController {

    @Autowired
    private KafkaTemplate<String,String> kafkaTemplate;

    @RequestMapping("test")
    public String test1() {
        return "success";
    }

    @RequestMapping("test2")
    public String test2(@RequestParam(value = "age", defaultValue = "18") int age, @RequestParam("name") String name) {
        return "success";
    }

    @RequestMapping("applog")
    public String getLogger(@RequestParam("param") String jsonStr){
        //打印日志
//        System.out.println(jsonStr);
        //将数据落盘
        log.info(jsonStr);
//        log.debug(jsonStr);
//        log.warn(jsonStr);
//        log.error(jsonStr);
//        log.trace(jsonStr);

        //将数据写入到Kafka
        kafkaTemplate.send("ods_base_log",jsonStr);

        return "success";
    }
}
